# /usr/bin/env python
# coding: utf-8
'''
python 命令行参数解析.py         #监听8000
python 命令行参数解析.py --port=9999     #监听9999
python 命令行参数解析.py --port=9999  --list=1,2,3    #返回['1','2','3']
'''

import tornado.web
import tornado.ioloop
import tornado.httpserver
import tornado.options

tornado.options.define("port", default=8000, type=int, help="run server on given port, default 8000")
tornado.options.define("list", default=[], type=str, multiple=True, help="str list separe by ','")

class IndexHandler(tornado.web.RequestHandler):
    '''主路由处理类'''
    def get(self):
        '''对应http get请求'''
        print(tornado.options.options.list)
        self.write(",".join(tornado.options.options.list))

if __name__ == '__main__':
    tornado.options.parse_command_line()
    app = tornado.web.Application([
        (r'/', IndexHandler),
    ])
    http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(tornado.options.options.port)
    tornado.ioloop.IOLoop.current().start()
